﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace _2011DBProject
{
    public partial class Channel : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!((Session["USER"]) == null) || !((Session["SERVER"]) == null))
            {
                lblCh.Text = (string)(Session["CHARACTER_NAME"]);
                //Settings.strCharacterName = tmpLabel.Text;
                lblServer.Text = (Session["SERVER"]).ToString();
                Label templbl = (Label)(DataList3.Controls[0].Controls[1]).FindControl("lblDLServer");
                lblServer.Text = templbl.Text;
            }
            else
            {
                Response.Redirect("Default.aspx?isNoSession=1");
            }
        }

        protected void gvChannel_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataSet1.ACCOUNTDataTable dsaccount = new DataSet1.ACCOUNTDataTable();
            DataSet1TableAdapters.ACCOUNTTableAdapter dsaccountta = new _2011DBProject.DataSet1TableAdapters.ACCOUNTTableAdapter();
            
            if (gvChannel.DataKeys[gvChannel.SelectedIndex].Value.ToString() == "1")
            {
                if (Convert.ToInt32(dsaccountta.GetDataByACCOUNT_ID(Settings.strAccountID)[0].GRADE_NO) < 2)
                {
                    lblgrade.Text = "골드등급 이상만 입장할 수 있습니다.";
                    lblgrade.Visible = true;
                    Button1.Visible = false;
                }
                else
                {
                    lblgrade.Visible = false;
                    Button1.Text = gvChannel.DataKeys[gvChannel.SelectedIndex].Value.ToString() + "번 채널로 입장하기!";
                    Button1.Visible = true;
                }
            }
            else
            {
                lblgrade.Visible = false;
                Button1.Text = gvChannel.DataKeys[gvChannel.SelectedIndex].Value.ToString() + "번 채널로 입장하기!";
                Button1.Visible = true;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Session.Add("Ch", gvChannel.DataKeys[gvChannel.SelectedIndex].Value.ToString());
            //Settings.RefreshCh();
            //enterChannel();
            Response.Redirect("Gameroom.aspx");
        }

        private void enterChannel()
        {
            try
            {
                DataSet1.CHANNEL_ENTRANCE_STATUSDataTable chEntrance = new DataSet1.CHANNEL_ENTRANCE_STATUSDataTable();
                DataSet1TableAdapters.CHANNEL_ENTRANCE_STATUSTableAdapter taChEntrance = new _2011DBProject.DataSet1TableAdapters.CHANNEL_ENTRANCE_STATUSTableAdapter();
                DataSet1.CHANNEL_ENTRANCE_STATUSRow row = chEntrance.NewCHANNEL_ENTRANCE_STATUSRow();
               
                row.CHANNEL_NO = Settings.decCh;
                row.CHARACTER_NAME = Settings.strCharacterName;
                row.SERVER_NO = Settings.decServer;
                chEntrance.AddCHANNEL_ENTRANCE_STATUSRow(row);
                taChEntrance.Update(chEntrance);
            }
            catch (Exception)
            {

            }
        }
        protected void btnGoLogout_onclick(object sender, EventArgs e)
        {
            Session.Clear();
            Response.Redirect("Default.aspx");
        }
        protected void btnGoServer_onclick(object sender, EventArgs e)
        {
            Response.Redirect("Server.aspx");
        }
        protected void btnGoCharacter_onclick(object sender, EventArgs e)
        {
            Response.Redirect("Character.aspx");
        }
    }
}
